/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pv168.uloha3.swing.workers;

import cz.muni.fi.pv168.uloha3.common.DBUtils;
import cz.muni.fi.pv168.uloha3.entities.Owner;
import cz.muni.fi.pv168.uloha3.entities.Ownership;
import cz.muni.fi.pv168.uloha3.entities.RealEstate;
import cz.muni.fi.pv168.uloha3.managers.impl.OwnerManagerImpl;
import cz.muni.fi.pv168.uloha3.managers.impl.OwnershipManagerImpl;
import cz.muni.fi.pv168.uloha3.managers.impl.RealEstateManagerImpl;
import cz.muni.fi.pv168.uloha3.swing.OwnersTableModel;
import cz.muni.fi.pv168.uloha3.swing.SwingGuiMain;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sql.DataSource;
import javax.swing.JTable;
import javax.swing.SwingWorker;

/**
 *
 * @author stefan
 */
public class ListOwnerEstatesSwingWorker extends SwingWorker<Set<RealEstate>, Object> {
    //private OwnersTableModel modelOwners = (OwnersTableModel) jTableOwnerAllOwners.getModel();
    
    private final JTable table;
    
    DataSource dataSource = DBUtils.initConnector();
    RealEstateManagerImpl estateManager = new RealEstateManagerImpl();
    OwnershipManagerImpl ownershipManager = new OwnershipManagerImpl();
    OwnerManagerImpl ownerManager = new OwnerManagerImpl();
    //Set<Ownership> ownerships = new TreeSet<Ownership>();
    Set<RealEstate> estates = new TreeSet<RealEstate>();
    
    public ListOwnerEstatesSwingWorker(JTable table) {
        this.table = table;
    }

    @Override
    protected Set<RealEstate> doInBackground() throws Exception {

        ownerManager.setDataSource(dataSource);
        ownershipManager.setDataSource(dataSource);
        estateManager.setDataSource(dataSource);

        int col = table.getSelectedColumn();
        int row = table.getSelectedRow();
        Object value = table.getValueAt(row, 0);
        Long id = new Long(value.toString());
        Owner selectedOwner = null;

        selectedOwner = ownerManager.getOwnerById(new Long(id));
        Set<Ownership> ownerships = ownershipManager.getOwnershipsByOwner(selectedOwner);
        Logger.getLogger(SwingGuiMain.class.getName()).log(Level.SEVERE, " blab");

        return null;
    }
}